package edu.ustb.service.xiumi.impl;

import edu.ustb.domain.user.Users;
import edu.ustb.mapper.user.UsersDao;
import edu.ustb.service.xiumi.xiumiMailControllerService;
import edu.ustb.utils.MybatisUtil;
import org.apache.commons.lang3.StringUtils;

public class xiumiMailControllerServiceImpl implements xiumiMailControllerService {
    @Override
    public boolean verifyInfoByMail(String info, String mail) {
        System.out.println(info + "  " + mail);
        UsersDao mapper = MybatisUtil.getMapper(UsersDao.class);

        // 判断 info 信息是 phone 还是 name
        if(StringUtils.isNumeric(info)){
            // 说明 info 是 phone
            Users byPhoneNum = mapper.findByPhoneNum(info);
            Users phoneIdItem =
                    mapper.selectByPrimaryKey(byPhoneNum.getUserId());
            MybatisUtil.close();
            // 邮箱校验结果返回
            return phoneIdItem.getUserEmail().equals(mail);

        }else{
            // 说明 info 是 name
            Users byName = mapper.findBy(info);
            Users nameId = mapper.selectByPrimaryKey(byName.getUserId());
            MybatisUtil.close();
            // 邮箱校验结果返回
            return nameId.getUserEmail().equals(mail);
        }
    }
}
